<script type="text/html" template lay-done="layui.data.sendParams(d.params)"></script>
<div class="layui-tab layui-tab-brief" lay-filter="userDetailInfo">
    <ul class="layui-tab-title">
        <li class="layui-this" lay-id="base">基本信息</li>
        <li lay-id="log">操作日志</li>
    </ul>
    <div class="layui-tab-content">
        <!--基本资料-->
        <div class="layui-tab-item layui-show">
            <div class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-block">
                        <script type="text/html" template>
                            <input type="text" name="account" value="{{ d.params.account || '' }}" class="layui-input"
                                   readonly>
                        </script>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">实名状态</label>
                    <div class="layui-input-block">
                        <script type="text/html" template>
                            <input type="text" name="auth" value="{{ d.params.check===1?'启用':'禁用' }}"
                                   class="layui-input" readonly>
                        </script>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机号码</label>
                    <div class="layui-input-block">
                        <script type="text/html" template>
                            <input type="text" name="mobile" value="{{ d.params.mobile || '' }}" class="layui-input"
                                   readonly>
                        </script>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">最近登陆</label>
                    <div class="layui-input-block">
                        <script type="text/html" template>
                            <input type="text" name="lastLoginTime"
                                   value="{{ layui.util.toDateString(d.params.lastLoginTime, 'yyyy-MM-dd HH:mm:ss') }}"
                                   class="layui-input" readonly>
                        </script>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">注册时间</label>
                    <div class="layui-input-block">
                        <script type="text/html" template>
                            <input type="text" name="createdAt"
                                   value="{{ layui.util.toDateString(d.params.createdAt, 'yyyy-MM-dd HH:mm:ss') }}"
                                   class="layui-input" readonly>
                        </script>
                    </div>
                </div>
            </div>
        </div>

        <!--操作日志-->
        <div class="layui-tab-item">
            <table id="LAY-admin-log" lay-filter="LAY-admin-log"></table>
        </div>
    </div>

</div>

<script>

    layui.data.sendParams = function (params) {
        layui.use(['admin', 'form', 'element', 'setter'], function () {
            var $ = layui.$
                , admin = layui.admin
                , form = layui.form
                , setter = layui.setter
                , table = layui.table
                , element = layui.element;

            var user = params;

            var apiUrl = setter.apiUrl;

            element.on('tab(userDetailInfo)', function (data) {
                var tabId = this.getAttribute('lay-id');
                switch (tabId) {
                    case 'log':
                        log();
                        break;
                    case 'other':
                        log();
                        break;
                    default:
                        break;
                }
            });

            function log() {
                table.render({
                    elem: '#LAY-admin-log',
                    url: apiUrl + '/mapi/admin/log/list',
                    method: 'post',
                    page: true,
                    contentType: 'application/json',
                    headers: {
                        'token': layui.data(setter.tableName).token
                    },
                    request: {
                        pageName: 'pageNo', limitName: 'pageSize'
                    },
                    where: {adminId: user.id},
                    response: {
                        statusCode: 0
                    },
                    parseData: function (res) {
                        if (res.code === 0) {
                            //将原始数据解析成 table 组件所规定的数据
                            return {
                                "code": res.code, //解析接口状态
                                "msg": res.msg, //解析提示文本
                                "count": res.data.total, //解析数据长度
                                "data": res.data.list //解析数据列表
                            };
                        } else {
                            return {
                                "code": res.code, //解析接口状态
                                "msg": res.msg, //解析提示文本
                            };
                        }
                    },
                    cols: [[
                        {
                            field: 'createdAt',
                            title: '创建时间',
                            templet: '<div>{{layui.util.toDateString(d.createdAt, "yyyy-MM-dd HH:mm:ss")}}</div>'
                        }, {field: 'type', title: '类型', templet: '<div>{{d.type==0?"登陆日志":"操作日志"}}</div>'}
                        , {field: 'subject', title: '主题'}
                        , {field: 'content', title: '内容'}
                    ]]
                    , text: {
                        none: '未检索到数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                    }
                });
            }


        });
    };
</script>